package com.elinkway.infinitemovies.http.requesttask;

import android.content.Context;
import android.os.Bundle;

import com.elinkway.infinitemovies.async.MoviesHttpAsyncTask;
import com.elinkway.infinitemovies.bean.CommonBean;
import com.elinkway.infinitemovies.bean.PlayStatusReporter;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.http.parser.CommonParser;
import com.lvideo.http.bean.LVideoDataHull;

/**
 * Author: liuxiaojiang(liuxiaojiang@lvideo.com)
 * Date: 2016-09-26
 * Time: 10:32
 * Description: 播放结果数据上报
 */
public class ReportPlayStatusTask extends
        MoviesHttpAsyncTask<CommonBean> {

    private PlayStatusReporter playStatus;

    @Override
    public void netNull() {
        super.netNull();
    }

    @Override
    public void netErr(int updateId, String errMsg) {
        super.netErr(updateId, errMsg);
    }

    @Override
    public void dataNull(int updateId, String errMsg) {
        super.dataNull(updateId, errMsg);
    }

    public ReportPlayStatusTask(Context context, PlayStatusReporter playStatus) {
        super(context);
        this.playStatus = playStatus;
    }

    @Override
    public LVideoDataHull<CommonBean> doInBackground() {
        if(playStatus == null){
            return null;
        }
        Bundle params = new Bundle();
        params.putString("state", playStatus.getState());
        params.putString("action", playStatus.getAction());
        params.putString("subsrc", playStatus.getSubsrc());
        params.putString("vid", playStatus.getVid());
        params.putString("aid", playStatus.getAid());
        params.putString("porder", playStatus.getPorder());
        params.putString("httpcode", playStatus.getmHttpCode());
        params.putString("responsedata", playStatus.getmResponsedata());
        params.putString("cloucId", playStatus.getmCloudId());
        params.putString("errorinfo", playStatus.getmErrorInfo());
        params.putString("external_id", playStatus.getExternal_id());
        params.putString("global_vid", playStatus.getGlobal_vid());
        params.putString("vt",playStatus.getVt());
        params.putString("retry",playStatus.getRetry());
        if(playStatus.getSrartRequestTime() != 0 && playStatus.getEndRequestTime() != 0){
            params.putString("wait1", playStatus.getEndRequestTime() - playStatus.getSrartRequestTime() + "");
        }else{
            params.putString("wait1", "");
        }

        if(playStatus.getSetUrlTime() != 0 && playStatus.getStartPlayTime() != 0){
            params.putString("wait2", playStatus.getStartPlayTime() - playStatus.getSetUrlTime() + "");
        }else{
            params.putString("wait2", "");
        }

        LVideoDataHull<CommonBean> ret = MoviesHttpApi.reportPlayStatus(
                new CommonParser(), params);
        return ret;
    }

    @Override
    public void onPostExecute(int updateId, CommonBean result) {

    }
}
